package com.rxjava;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.subjects.PublishSubject;

public class PublishSubjectDemo {

	public static void main(String[] args) {
		//PublishSubject比较容易理解，相对比其他Subject常用，它的Observer只会接收到PublishSubject被订阅之后发送的数据。
		PublishSubject<String> publishSubject = PublishSubject.create();
		publishSubject.onNext("publishSubject1");
		publishSubject.onNext("publishSubject2");
		publishSubject.subscribe(new Observer<String>() {
			@Override
			public void onComplete() {

			}

			@Override
			public void onError(Throwable e) {

			}

			@Override
			public void onNext(String s) {
				System.out.println("publishSubject observer1:" + s);
			}

			@Override
			public void onSubscribe(Disposable disposable) {

			}
		});
		publishSubject.onNext("publishSubject3");
		publishSubject.onNext("publishSubject4");
	}

}
